package com.zq.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class ResultVo<T>{
    private Integer code;
    private String msg;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;
    public static <T> ResultVo<T> success(String msg){
        ResultVo<T> resultVo= new ResultVo<>();
        resultVo.setCode(ResultEnum.SUCCESS.getCode())
                .setMsg(msg);
        return resultVo;
    }
    public static <T> ResultVo<T> success(String msg,T data){
        ResultVo<T> resultVo= new ResultVo<>();
        resultVo.setCode(ResultEnum.SUCCESS.getCode())
                .setMsg(msg)
                .setData(data);
        return resultVo;
    }
    public static <T> ResultVo<T> fail(String msg){
        ResultVo<T> resultVo= new ResultVo<>();
        resultVo.setCode(ResultEnum.FAIL.getCode())
                .setMsg(msg);
        return resultVo;
    }

    public static <T> ResultVo<T> error(String msg) {
        ResultVo<T> resultVo = new ResultVo<>();
        resultVo.setCode(ResultEnum.ERROR.getCode())
                .setMsg(msg);
        return resultVo;
    }

    public static <T> ResultVo<T> invalid(String msg) {
        ResultVo<T> resultVo = new ResultVo<>();
        resultVo.setCode(ResultEnum.INVALID.getCode())
                .setMsg(msg);
        return resultVo;
    }
}

enum ResultEnum {
    SUCCESS(200),
    INVALID(300),
    FAIL(400),
    ERROR(500);
    private Integer code;

    ResultEnum(Integer code) {
        this.code=code;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
